package com.ruyixing.shopmanager.utils;

import android.widget.ImageView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;

public class ImageUtils {

	private static final DisplayImageOptions sImageDisplayOptions = new DisplayImageOptions.Builder()
			.imageScaleType(ImageScaleType.EXACTLY).cacheInMemory().build();
	
	public static void displayImage(String uri, ImageView imageView) {
		displayImage(uri, imageView, sImageDisplayOptions);
	}

	public static void displayImage(String uri, ImageView imageView,
			DisplayImageOptions options) {
		displayImage(uri, imageView, options, null);
	}

	public static void displayImage(String uri, ImageView imageView,
			DisplayImageOptions options, ImageLoadingListener listener) {
		try {

			String imageUri = uri;
			if (uri != null && uri.length() > 0) {
				if (uri.startsWith("/"))
					imageUri = "file://" + uri;

			}

			if (listener == null) {
				ImageLoader.getInstance().displayImage(imageUri, imageView,
						options);
			} else {
				ImageLoader.getInstance().displayImage(imageUri, imageView,
						options, listener);
			}
		} catch (OutOfMemoryError e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
